 selectInformation =new Vue({
    el:'#selectInformation',
    data:{
        selectWhich:'1',
        guestStatus:'1',
        selectName:'',
        roomNum:'',
        name:'',
        identity:'',
        tel:'',
        recordList:[],
        selectContent:[]
    },
    methods:{
        select:function(){
            $.ajax({
                url:'selectData',
                type:'POST',
                cache:false,
                dataType:'json',
                data:{
                    'selectwhich':this.selectWhich,
                    'guestStatus':this.guestStatus,
                    'selectName':this.selectName
                },
                success:function(data){
                    if(data.status == "error"){
                        alert(data.info);
                        return;
                    }
                    var modificationDtos = data.info;
                    console.log(modificationDtos);
                    selectInformation.recordList=[];
                    for (var i =0;i<modificationDtos.length;i++){
                        selectInformation.recordList.push({
                            name:modificationDtos[i].name,
                            roomNum:modificationDtos[i].roomNum,
                            identity:modificationDtos[i].identity,
                            overDay:modificationDtos[i].deadline
                        })
                    }
                },
                error:function(){
                    alert("请刷新网络")
                }
            })
        },
        downloadRecord:function(){
           var str = '<tr>' +
               '<td>姓名</td>' +
               '<td>房号</td>' +
               '<td>身份证</td>' +
               '<td>到期</td>' +
               '</tr>'
            for(var i=0;i<this.recordList.length;i++){
                str+='<tr>';
                for(item in this.recordList[i]){
                    var cellvalue = this.recordList[i][item];
                    str+=`<td style="mso-number-format:'\@';">${cellvalue}</td>`;
                }
                str+='</tr>';
            }
            var worksheet = '导出查询结果';
            var uri = 'data:application/vnd.ms-excel;base64,';
            //下载的表格模板数据
            var template = `<html xmlns:o="urn:schemas-microsoft-com:office:office"  
                            xmlns:x="urn:schemas-microsoft-com:office:excel"  
                            xmlns="http://www.w3.org/TR/REC-html40">  
                            <head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>  
                            <x:Name>${worksheet}</x:Name>  
                            <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>  
                            </x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->  
                            <head><meta charset='UTF-8'><body><table>${str}</table></body></html>`;
            //下载模板
            function base64 (s) { return window.btoa(unescape(encodeURIComponent(s)))}
            window.location.href = uri + base64(template);
        },
        inspect:function(){
            $.ajax({
                url:'selectModification',
                type:'POST',
                cache:false,
                dataType:'json',
                data:{
                    'roomNum':this.roomNum,
                    'name':this.name
                },
                success:function(data){
                    if(data.status == "error"){
                        alert(data.info);
                        return;
                    }
                    selectInformation.selectContent=[];
                    var modificationDtos = data.info;
                    console.log(modificationDtos);
                    for(var i=0;i<modificationDtos.length;i++){
                        selectInformation.selectContent.push({
                            id:modificationDtos[i].id,
                            name:modificationDtos[i].name,
                            tel:modificationDtos[i].tel,
                            identity:modificationDtos[i].identification
                        });
                        console.log(selectInformation.selectContent);
                    }


                },
                error:function(){
                    alert("请刷新网络")
                }
            })
        },
        modification:function(item){
            $.ajax({
                url:'modification',
                type:'POST',
                cache:false,
                dataType:'json',
                data:{
                    name : item.name,
                    tel : item.tel,
                    identification : item.identity,
                    id : item.id
                },
                success:function(data){
                    if(data.status == "error"){
                        alert(data.info);
                        return;
                    }
                    alert(data.info + " 姓名 ： "+data.content.name + " 电话号码 : "+data.content.tel+" 身份证 ： " + data.content.idetifcation);

                },
                error:function(){
                    alert("请刷新网络")
                }
            })
        }

    }
})